package com.zhima.service;

import cn.hutool.core.util.StrUtil;

import static com.zhima.exception.ErrorCode.CHECK_CODE_HAS_EXPIRED;
import static com.zhima.exception.ErrorCode.CHECK_CODE_WRONG;

public interface CheckCodeService {
    String sendCheckCode(String address);

    String getCheckCode(String address);

    default String verifyCheckCode(String address, String submitCheckCode) {
        String checkCode = getCheckCode(address);
        if (checkCode == null || StrUtil.isBlank(checkCode)) {
            return CHECK_CODE_HAS_EXPIRED.getErrorMessage();
        }
        if (!checkCode.equals(submitCheckCode)) {
            return CHECK_CODE_WRONG.getErrorMessage();
        }
        return "";
    }
}
